<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;

use app\common\model\QuestionCategory;

/**
 * 在线解答
 */
class Answer extends AdminBase
{
    
    /**
     * 在线解答列表
     */
    public function articleList()
    {
        
        $where= $this->logicAnswer->getWhere($this->param);

        $this->assign('list', $this->logicAnswer->getArticleList($where, 'a.*,c.name as category_name', 'a.sort desc'));
        $this->assign('param', $this->param);
        $this->assign('cate', QuestionCategory::all(['status'=>1]));
        return $this->fetch('article_list');
    }
    
    /**
     * 在线解答添加
     */
    public function articleAdd()
    {
        
        $this->articleCommon();
        $this->assign('param', $this->param);
        $this->assign('cate', QuestionCategory::all(['status'=>1]));
        return $this->fetch('article_edit');
    }
    
    /**
     * 在线解答编辑
     */
    public function articleEdit()
    {
        
        $this->articleCommon();
        
        $info = $this->logicAnswer->getArticleInfo(['a.id' => $this->param['id']], 'a.*');


        $this->assign('cate', QuestionCategory::all(['status'=>1]));
        $this->assign('info', $info);
        
        return $this->fetch('article_edit');
    }
    
    /**
     * 在线解答添加与编辑通用方法
     */
    public function articleCommon()
    {
        
//      IS_POST && $this->jump($this->logicAnswer->articleEdit($this->param));
        IS_POST && $this->jump($this->logicAnswer->articleEdit($_POST));


    }
    

    
    /**
     * 数据状态设置
     */
    public function setStatus()
    {
        
        $this->jump($this->logicAdminBase->setStatus('CourseQuestion', $this->param));
    }

    /**
     * 数据状态设置
     */
    public function update_info()
    {

        $this->jump($this->logicAnswer->update_info( $this->param));
    }


    /**
     * 问题分类添加
     */
    public function articleCategoryAdd()
    {

        IS_POST && $this->jump($this->logicAnswer->articleCategoryEdit($this->param));

        return $this->fetch('answer_category_edit');
    }

    /**
     * 问题分类编辑
     */
    public function articleCategoryEdit()
    {

        IS_POST && $this->jump($this->logicAnswer->articleCategoryEdit($this->param));

        $info = $this->logicAnswer->getArticleCategoryInfo(['id' => $this->param['id']]);
        $this->assign('info', $info);

        return $this->fetch('answer_category_edit');
    }

    /**
     * 问题分类列表
     */
    public function articleCategoryList()
    {

        $this->assign('list', $this->logicAnswer->getArticleCategoryList([],'*','sort desc'));
        return $this->fetch('answer_category_list');
    }

    /**
     * 文章分类删除
     */
    public function articleCategoryDel($id = 0)
    {

        $this->jump($this->logicAdminBase->setStatus('QuestionCategory', $this->param));
    }


    /**
     * 排序
     */
    public function setSort()
    {

        $this->jump($this->logicAdminBase->setSort('CourseQuestion', $this->param));
    }


    /**
     * 排序
     */
    public function CateSetSort()
    {

        $this->jump($this->logicAdminBase->setSort('QuestionCategory', $this->param));
    }
}
